package com.itic.mall.system.pay.withDrawals.service;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.appbase.framework.type.WithDrawalsType;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.mall.system.inter.pay.withDrawals.persistence.dao.WithDrawalsRecordDao;
import com.itic.mall.system.inter.pay.withDrawals.persistence.model.WithDrawalsRecord;
import com.itic.mall.system.inter.pay.withDrawals.persistence.model.WithDrawalsRecordExample;
import com.itic.mall.system.inter.pay.withDrawals.persistence.model.WithDrawalsRecordExample.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class WithDrawalsRecordService
     extends CrudService<WithDrawalsRecordDao,WithDrawalsRecord,WithDrawalsRecordExample> {
    @Autowired
    private WithDrawalsRecordDao withDrawalsRecordDao;
    
    public void addWithDrawalsRecord(double amount,String aliName,String aliAccount,String payUserLogId,String phone,double fee,String userId ) {
    	WithDrawalsRecord record = new WithDrawalsRecord();
		record.setAccount(amount-fee);
		record.setAliPayLoginName(aliAccount);
		record.setAliPayName(aliName);
		record.setPayUserLogId(payUserLogId);
		record.setPhone(phone);
		record.setStatus(WithDrawalsType.apply.getType());
		record.setWithdrawFee(fee);
		record.setUserId(userId);
		this.add(record);
    }
    /**
     * 根据支付日志ID查找
     * @param payUsrelogId
     * @return
     */
    public WithDrawalsRecord getWithDrawalsRecordByPayUserlogId(String payUsrelogId){
    	WithDrawalsRecord record = null;
    	if(StringHelper.isNotBlank(payUsrelogId)){
    		WithDrawalsRecordExample example = new WithDrawalsRecordExample();
    		Criteria criteria = example.createCriteria();
    		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    		criteria.andPayUserLogIdEqualTo(payUsrelogId);
    		List<WithDrawalsRecord> list = this.withDrawalsRecordDao.selectByExample(example);
    		if(list.size()>0){
    			record = list.get(0);
    		}
    	}
    	return record;
    }
}